// pages/tenantsdetail/tenantsdetail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    store_id: 0,
    storeItem: {},

    hideHeader: true,
    hideBottom: true,
    refreshTime: '', // 刷新的时间 
    allPages: '', // 总页数
    currentPage: 1, // 当前页数  默认是1
    loadMoreData: '加载更多……',

    pinglun_list: [],
    isHiddenMes1: true,
    pinglun_num: 216, //评论数量
    averageScore: 4.9, //平均分数
    zan_num: 129, //点赞数量

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    var date = new Date();
    this.setData({
      refreshTime: date.toLocaleTimeString()
    })

    console.log(options.id);

    this.setData({
      store_id: options.id
    })

    this.getStoreData(options.id);

    //获取评论列表的数据
    this.getData(options.id);

  },
  /*
  *美食商户详情数据
  */
  getStoreData: function (id) {

    var that = this;

    app.apiPost(app.apiList.enjoy_detail, {
      content: {
        id: id
      }
    }, function (res) {
      console.log(res.content, '娱乐商户详情');
      that.setData({
        storeItem: res.content
      })
    })
  },
  // 上拉加载更多
  loadMore: function () {
    var self = this;
    // 当前页是最后一页
    if (self.data.currentPage == self.data.allPages) {
      self.setData({
        loadMoreData: '已经到顶'
      })
      return;
    }
    setTimeout(function () {
      console.log('上拉加载更多');
      var tempCurrentPage = self.data.currentPage;
      tempCurrentPage = tempCurrentPage + 1;
      self.setData({
        currentPage: tempCurrentPage,
        hideBottom: false
      })
      self.getData(this.data.store_id);
    }, 300);

  },
  // 下拉刷新
  refresh: function (e) {
    var self = this;
    setTimeout(function () {
      console.log('下拉刷新');
      var date = new Date();
      self.setData({
        currentPage: 1,
        refreshTime: date.toLocaleTimeString(),
        hideHeader: false
      })
      self.getData(this.data.store_id);
    }, 300);

  },
  /*
  *获取评论列表
  */
  getData: function (id) {
    var self = this;
    var pageIndex = self.data.currentPage;

    console.log(self.data.storeItem,'0000');

    // page: pageIndex
    app.apiPost(app.apiList.meishi_comment_list, {
      content: {
        siteId: self.data.store_id,
        pageNum: pageIndex,
        pageSize: 20
      }
    }, function (res) {
      console.log(res, '娱乐商户评论', res.content.list);

      var pinglun_list = res.content.pageData.list;

      if (pageIndex == 1) { // 下拉刷新
        self.setData({
          allPages: res.content.pageData.total,
          pinglun_list: pinglun_list,
          hideHeader: true
        })

      } else { // 加载更多
        var tempArray = self.data.pinglun_list;
        tempArray = tempArray.concat(pinglun_list);
        self.setData({
          allPages: res.content.pageData.total,
          pinglun_list: tempArray,
          hideBottom: true
        })
      }

      if (self.data.pinglun_list.length > 0) {
        self.setData({
          isHiddenMes1: false
        })
      }
    })

  },
  /*
  *团购
  */
  groupPurchase: function () {
    console.log('团购');
    wx.navigateTo({
      url: '../tuangou/tuangou',
    })
  },
  /*
 *订座
 */
  reservations: function () {
    console.log('订座');

    wx.navigateTo({
      url: '../bookenjoy/bookenjoy',
    })
  },
  /*
  *导航
  */
  searchDaohang: function () {
    console.log('查看导航');
    // https://blog.csdn.net/qq_35713752/article/details/79141034
    var obj = {};
    obj.name = this.data.storeItem.name;
    obj.lat = this.data.storeItem.lat;
    obj.lng = this.data.storeItem.lng;
    obj.address = this.data.storeItem.address;

    obj = JSON.stringify(obj);

    wx.navigateTo({
      url: '../shopnavigate/shopnavigate?storeInfo=' + obj,
    })

  },
  cellPhone: function () {
    console.log('拨打电话');
    var phone = this.data.storeItem.phone;
    wx.makePhoneCall({
      phoneNumber: phone,
    })
  },
  searchAllPL: function () {
    console.log('查看所有评论');
    var that = this;
    wx.navigateTo({
      url: '../allcomment/allcomment?siteId=' + that.data.store_id,
    })
  },
  yaoPinglun: function () {
    // console.log('我要评论');
    // wx.navigateTo({
    //   url: '../publishcomment/publishcomment',
    // })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

// https://jingyan.baidu.com/album/5552ef47876faf518ffbc9d9.html?picindex=3 拨打电话功能